package com.xinghanlaser.applet.controller;

import com.xinghanlaser.applet.base.common.entity.ResponseEntity;
import com.xinghanlaser.applet.query.KnowledgeQuery;
import com.xinghanlaser.applet.service.IKnowledgeBaseService;
import com.xinghanlaser.applet.vo.applet.KnowledgePostVO;
import com.xinghanlaser.applet.vo.applet.KnowledgePutVO;
import com.xinghanlaser.applet.vo.applet.KnowledgeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 *
 * <p>
 *
 * @author: mftuo 陀铭峰
 * @since: 2024/5/6 10:08
 */
@RestController
@RequestMapping("/knowledge")
@Api(value = "知识库管理", tags = "知识库管理")
public class KnowledgeController {

    @Resource
    private IKnowledgeBaseService service;

    @GetMapping
    @ApiOperation("根据条件分页查询知识库")
    public ResponseEntity<ResponseEntity.PageResult<KnowledgeVO>> pageByCondition(@Valid KnowledgeQuery query){
        return  service.pageByCondition(query);
    }

    @GetMapping("/{knowledgeId}")
    @ApiOperation("根据ID查询知识库")
    public ResponseEntity<KnowledgeVO> getKnowledgeById(@PathVariable("knowledgeId")Long id){
        return service.getKnowledgeById(id);
    }

    @PostMapping
    @ApiOperation("创建知识")
    public ResponseEntity<Void> addKnowledge(@RequestBody @Valid KnowledgePostVO postVO){
        return service.addKnowledge(postVO);
    }

    @PutMapping
    @ApiOperation("修改知识")
    public ResponseEntity<Void> modKnowledge(@RequestBody @Valid KnowledgePutVO putVO){
        return service.modKnowledge(putVO);
    }
}
